/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file ce_utils.h
 * @brief 卡模拟模块相关的工具函数定义
 */

#ifndef _CE_UTILS_H_
#define _CE_UTILS_H_

#include "nci_feature.h"
#include "nfa_ce.h"
#include "ce_techs.h"
#include "nci_base.h"

#if IS_FEATURE_ON(NCI_FEATURE_CE_DH)
/**
 * @brief CE模块链表节点结构体
 */
typedef struct Node {
    /** @brief 监听技术类型 */
    tNCI_CE_TECH tech;
    union {
        /** @brief  T3T监听参数 */
        tCE_T3T_LISTEN listen_t3t;
    };
    /** @brief 下一个节点指针 */
    struct Node *next;
} tCE_NODE;

/**
 * @brief CE模块链表结构体
 */
typedef struct {
    tCE_NODE *head;
    size_t count;
} tCE_LIST;
#endif // IS_FEATURE_ON(NCI_FEATURE_CE_DH)

/**
 * @brief 获取指定CE技术的API接口
 *
 * @param[in] tech CE技术类型
 *
 * @return 返回对应的CE技术API指针，失败返回NULL
 */
tNCI_CE_ACTS* ce_utils_get_acts(tNCI_CE_TECH tech);

#if IS_FEATURE_ON(NCI_FEATURE_CE_DH)
/**
 * @brief 创建一个新的链表节点
 *
 * @return 返回新的节点指针，失败返回NULL
 */
tCE_NODE *ce_node_create();

/**
 * @brief 销毁链表节点
 *
 * @param[in] node 要销毁的节点指针
 */
void ce_node_destroy(tCE_NODE *node);

/**
 * @brief 创建一个新的链表
 *
 * @return 返回新的链表指针，失败返回NULL
 */
tCE_LIST *ce_list_create();

/**
 * @brief 在链表头部添加节点
 *
 * @param[in] list 链表指针
 * @param[in] node 要添加的节点指针
 * @return 成功返回true，失败返回false
 */
bool ce_list_add_first(tCE_LIST *list, tCE_NODE *node);

/**
 * @brief 在链表尾部添加节点
 *
 * @param[in] list 链表指针
 * @param[in] node 要添加的节点指针
 * @return 成功返回true，失败返回false
 */
bool ce_list_add_last(tCE_LIST *list, tCE_NODE *node);

/**
 * @brief 从链表中删除节点
 *
 * @param[in] list 链表指针
 * @param[in] node 要删除的节点指针
 * @return 成功返回true，失败返回false
 */
bool ce_list_delete_node(tCE_LIST *list, tCE_NODE *node);

/**
 * @brief 销毁链表
 *
 * @param[in] list 要销毁的链表指针
 */
void ce_list_destroy(tCE_LIST *list);
#endif // IS_FEATURE_ON(NCI_FEATURE_CE_DH)

#endif /* _CE_UTILS_H_ */
